#include<sys/types.h>
#include<sys/msg.h>
#include<sys/ipc.h>
#define SHMKEY 75
int shmid, i;
int *addr;

CLIENT() {
		int i;
		shmid = shmget(SHMKEY, 1024, 0777|IPC_CREAT);
		addr = shmat(shmid, 0, 0);
		for(i = 9; i >= 0; i--){
				while(*addr != -1){
					printf("(client)sent\n");
				}
				*addr = i;
		}
		exit(0);
}

SERVER() {
		do {
				while(*addr == -1);
				printf("(server)received\n%d", *addr);
				if(*addr != 0){
						*addr = -1;
				}
		} while(*addr);
		wait(0);
		shmctl(shmid, IPC_RMID, 0);
}

main() {
	shmid = shmget(SHMKEY, 1024, 0777|IPC_CREAT);
	addr = shmat(shmid, 0, 0);
	*addr = -1;
	if(fork()){
			SERVER();
	} else {
			CLIENT();
	}
}














